import { App } from '@vue/runtime-dom'
// Element Plus
import 'element-plus/dist/index.css'
import * as Icons from '@element-plus/icons'

import {
  // Basic 基础组件
  ElLink,
  ElButton,
  ElIcon,
  // Form 表单组件
  ElForm,
  ElFormItem,
  ElInput,
  ElSwitch,
  // Data 数据展示
  ElBadge,
  ElPagination,
  ElTimeline,
  ElTimelineItem,
  ElTag,
  // Navigation 导航
  ElDropdown,
  ElDropdownItem,
  ElDropdownMenu,
  // Feedback 反馈组件
  ElDialog,
  ElLoading,
  ElMessage,
  ElMessageBox,
  ElPopover,
  ElTooltip,

  ElAutocomplete,
  ElDivider
} from 'element-plus'

// 组件写在components中
export const components: any[] = [
  ElLink,
  ElButton,
  ElIcon,

  ElForm,
  ElFormItem,
  ElInput,
  ElSwitch,

  ElBadge,
  ElPagination,
  ElTimeline,
  ElTimelineItem,
  ElTag,

  ElDropdown,
  ElDropdownItem,
  ElDropdownMenu,
  ElPopover,

  ElDialog,
  ElTooltip,

  ElAutocomplete,
  ElDivider
]

// 插件写在plugins中
export const plugins: any[] = [ElMessageBox, ElMessage, ElLoading]

export default {
  install: (app:App) => {
    // 按需导入Element Plus组件和插件
    components.forEach(component => {
      app.component(component.name, component)
    })
    plugins.forEach(plugin => {
      app.use(plugin)
    })

    // 注册全局组件
    Object.keys(Icons).forEach(key => {
      app.component(key, Icons[key as keyof typeof Icons])
    })
  }
}
